package com.example.fragment;



import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.Activity.R;
import com.example.adapter.FruitAdapter;
import com.example.entity.Fruit;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends Fragment {
    View view;
    private List<Fruit> fruitList = new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.home_fragment,container,false);
        initFruits();
        RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        FruitAdapter adapter = new FruitAdapter(fruitList);
        recyclerView.setAdapter(adapter);

        return view;
    }

    private void initFruits() {
        for (int i=0;i<1;i++) {
            Fruit pear = new Fruit("雪糕", R.drawable.ms_1);
            fruitList.add(pear);
            Fruit strawberry = new Fruit("糖醋排骨", R.drawable.ms_2);
            fruitList.add(strawberry);
            Fruit watermelon = new Fruit("美味鸡翅", R.drawable.ms_3);
            fruitList.add(watermelon);
            Fruit grange = new Fruit("麻辣小龙虾", R.drawable.ms_4);
            fruitList.add(grange);
            Fruit grape = new Fruit("大闸蟹", R.drawable.ms_5);
            fruitList.add(grape);
            Fruit iango = new Fruit("麻婆豆腐", R.drawable.ms_6);
            fruitList.add(iango);
        }
    }
}
